package com.durian.base.frame.easyrouter;

import android.app.Activity;
import android.content.Intent;
import com.durian.base.utils.StringUtils;

/**
 * 说明：ActivityResult
 * <p/>
 * 作者：fanly
 * <p/>
 * 类型：Class
 * <p/>
 * 时间：2019-06-24 09:13
 * <p/>
 * 版本：version 1.0
 */
public class ActivityResult {

    private int requestCode;
    private int resultCode;
    private Intent intent;

    public ActivityResult(int requestCode,int resultCode,Intent intent){
        this.requestCode = requestCode;
        this.resultCode = resultCode;
        this.intent = intent;
    }

    public Intent getData() {
        return intent;
    }

    private boolean hasExtras(String...keys){
        boolean result = false;
        if (keys != null && keys.length > 0) {
            result = true;
            for (String key : keys) {
                if (StringUtils.isNotEmpty(key)) {
                    if (!intent.hasExtra(key)) {
                        result = false;
                        break;
                    }
                }
            }
        }
        return result;
    }

    public boolean isSuccess(String...keys){
        boolean result = false;
        if (requestCode == EasyRouter.EASY_REQUEST_CODE && resultCode == Activity.RESULT_OK){
            if (intent != null && intent.hasExtra(IntentBuilder.SUCCESS)){
                if (keys != null && keys.length > 0){
                    result = hasExtras(keys);
                }else {
                    result = true;
                }
            }
        }
        return result;
    }
}
